public class Solution152 {
    public int maxProduct(int[] nums) {
        int res = nums[0];
        int max = 1, min = 1;
        for (int num : nums) {
            int t = max;
            max = Math.max(max * num, Math.max(min * num, num));
            min = Math.min(min * num, Math.min(t * num, num));
            res = Math.max(res, max);
        }
        return res;
    }
}
